import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  Map data = {};
  @override
  Widget build(BuildContext context) {
    // 接收参数
    data = data.isNotEmpty?data: ModalRoute.of(context)?.settings.arguments as Map;
    print(data);
    //  type 'Null' is not a subtype of type 'bool'  类型不对
    print('类型:${data['isDayTime'].runtimeType}');
    // 设置背景图片
    String bgImage = data['isDayTime']?'day.png':'night.png';
    Color? bgColor =data['isDayTime']?Colors.blue:Colors.indigo[700];
    return Scaffold(
      backgroundColor: bgColor,
      body:SafeArea(
        child: Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage('assets/$bgImage'),
              fit: BoxFit.cover
            )
          ),
          child: Padding(
            padding: const EdgeInsets.fromLTRB(0,120,0,0),
            child: Column(
              children: [
                // 跳转
                FlatButton.icon(
                  onPressed:() async{
                    dynamic result = await Navigator.pushNamed(context, "/location");
                    if(result != null){
                      setState(() {
                        data = {
                          'location':result['location'],
                          'flag':result['flag'],
                          'time':result['time'],
                          'isDaytime':result['isDaytime']
                        };
                      });
                    }
                  },
                  icon:Icon(
                    Icons.edit_location,
                    color: Colors.blue[300],
                    ),
                  label: Text(
                    "Edit Location",
                    style: TextStyle(
                      color: Colors.red[300]
                    ),
                    ),
                  ),
                  SizedBox(height: 20.0),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        data['location'],
                        style: TextStyle(
                          fontSize: 28.0,
                          letterSpacing: 2.0,
                          color: Colors.deepOrangeAccent,
                        ),
                      )
                    ],
                  ),
                  SizedBox(height: 20.0),
                  Text(
                    data['time'],
                    style: TextStyle(
                      fontSize: 66.0,
                      color: Colors.deepOrange,
                    )
                  )
              ],
            ),
          ),
        )
      )
    );
    
  }
}